<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Crossline Products</title>
        <?php include 'protected/includes/head.php' ?>
        <link rel="stylesheet" type="text/css" href="protected/style/product.css"/>
        <script type="text/javascript" src="protected/js/jquery.smartCart-2.0.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){
    	// Call Smart Cart    	
  		$('#SmartCart').smartCart({
          onAdd: function(pObj,quantity){ return cartAdd(pObj,quantity);}, 
          onAdded: function(pObj,quantity){  cartAdded(pObj,quantity);},
          onRemove: function(pObj){return cartRemove(pObj);}, 
          onRemoved: function(pObj){ cartRemoved(pObj);}, 
          onUpdate: function(pObj,quantity){ return cartUpdate(pObj,quantity); }, 
          onUpdated: function(pObj,quantity){ cartUpdated(pObj,quantity); },  //  
          onCheckout: function(Obj){ cartCheckout(Obj); }  //  
      });
      // On add
      function cartAdd(obj,qty){
         var msg = "Can i add the product "+obj.attr("pname")+ " of quantity "+qty+" to cart?"; 
         $("#cartMessage").html("<strong>onAdd</strong> event trigged");
         return confirm(msg);
      }
      // On added
      function cartAdded(obj,qty){
         var msg = "I'm added the product "+obj.attr("pname")+ " of quantity "+qty+" to cart."; 
         $("#cartMessage").html("<strong>onAdded</strong> event trigged <br />Message: "+msg);
      }
      // On Remove
      function cartRemove(obj){
         var msg = "Can i remove the product "+obj.attr("pname")+ " from cart?"; 
         $("#cartMessage").html("<strong>onRemove</strong> event trigged");
         return confirm(msg);
      }
      // On Removed
      function cartRemoved(obj){
         var msg = "I'm removed the product "+obj.attr("pname")+ " from cart."; 
         $("#cartMessage").html("<strong>onRemoved</strong> event trigged <br />Message: "+msg);
      }
      // On Update
      function cartUpdate(obj,qty){
         var msg = "Can i update the quantity of the product "+obj.attr("pname")+ " to "+qty+"?"; 
         $("#cartMessage").html("<strong>onUpdate</strong> event trigged");
         return confirm(msg);
      }
      // On Updated
      function cartUpdated(obj,qty){
         var msg = "I'm updated the quantity of the product "+obj.attr("pname")+ " to "+qty+"?"; 
         $("#cartMessage").html("<strong>onUpdated</strong> event trigged <br />Message: "+msg);
      }
      // On Checkout
      function cartCheckout(obj){
         var msg = "I'm listing the product id, quantity of the selected products<br /> ";                
         obj.children("option").each(function(n) {                     
            var pValue = $(this).attr("value");
            var valueArray = pValue.split('|');
            var prdId = valueArray[0];
            var pQty = valueArray[1];
            msg += "ProductId: "+prdId+" Quantity: "+pQty+"<br />";

        });

         $("#cartMessage").html("<strong>onCheckout</strong> event trigged <br />Message: "+msg);
      }       
            
        $('.dialog').dialog({
            autoOpen: false,
            width: 600,
            buttons: {
                "Ok": function() {
                    $(this).dialog("close");
                }
            }
        });
        $('.scCheckoutButton').click(function(){
            $( ".dialog" ).dialog( "open" );
            //return false;
        });
        });
	</script>
    </head>
    <body>
        <div class="dialog" title="Create new user"> 
            <p class="validateTips">All form fields are required.</p> 
            <form action="GetInvolved" method="post"> 
                        <p><label for="name">Name:</label> 
                        <input maxlength="35" size="35" name="firstName" type="text" id="firstName" /> 
                        <span class="marker" title="This field is required.">*</span></p> 
 
                        <p><label for="email">E-mail:</label> 
                        <input maxlength="35" size="35" name="email" type="text" id="email"/> 
                        <span class="marker" title="This field is required.">*</span></p> 
 
                        <p><label for="contact">Contact No:</label> 
                        <input maxlength="35" size="35" name="contact" type="text" id="contact" /> 
 
                        <p><label for="address">Address:</label> 
                        <input maxlength="12" size="35" name="password" type="password" id="address" /> 
 
                        <hr /> 
                        <input value="submit" type="submit" id="submit" /> 
                    </form>
        </div> 
        <div id="main_cont">
            <?php
                $page="product";
                include 'protected/includes/header.php'
            ?>
            <div id="content_cont" class="ui-corner-all">
                <div id="product_cont" class="ui-corner-all">
                    <h2 class="ui-widget-header ui-corner-all">Products</h2><br />
                    <table align="center" border="0" cellpadding="0" cellspacing="0">
                        <tr><td>
                           <!-- <form action="#" method="post"> -->
                                <?php
                                    $con = mysql_connect("localhost","root","");
                                    if (!$con){
                                        die('Could not connect: ' . mysql_error());
                                    }
                                    mysql_select_db("crossline", $con);
                                    $result = mysql_query("SELECT * FROM product, category
                                        WHERE product.category_idcategory = category.idcategory
                                        AND product.active = 1");
                                    echo "<div id='SmartCart' class='scMain'>";

                                    while($row = mysql_fetch_array($result)){
                                        echo "<input type='hidden' pimage='" . $row['image'] . "' pname= '" . $row['name'] . 
                                        "' pprice='" . $row['price'] . "' pcategory='" . $row['category'] . "' pdesc='" 
                                        . $row['description'] . "' >";
                                     }
                                     echo "</div> ";
                                     echo"<input class = 'scCheckoutButton' type='submit' value='Check Out' />";
                                     mysql_close($con);
                                ?>
                               <!-- </form> -->
                            </td></tr>
                    </table>
                    
                </div>
            </div>
            <?php include 'protected/includes/footer.php' ?>
        </div>
    </body>
</html>
